package cn.mst.vrs.controller.admin.auth;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.mst.vrs.controller.admin.auth.vo.AuthPageReqVO;
import cn.mst.vrs.controller.admin.auth.vo.AuthRespVO;
import cn.mst.vrs.controller.admin.auth.vo.AuthSaveReqVO;
import cn.mst.vrs.service.auth.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 认证")
@RestController
@RequestMapping("/vrs/auth")
@Validated
public class VrsAuthController {

    @Resource
    private AuthService authService;

    @PostMapping("/create")
    @Operation(summary = "创建认证")
    @PreAuthorize("@ss.hasPermission('vrs:auth:create')")
    public CommonResult<Long> createAuth(@Valid @RequestBody AuthSaveReqVO createReqVO) {
        return success(authService.createAuth(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新认证")
    @PreAuthorize("@ss.hasPermission('vrs:auth:update')")
    public CommonResult<Boolean> updateAuth(@Valid @RequestBody AuthSaveReqVO updateReqVO) {
        authService.updateAuth(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除认证")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('vrs:auth:delete')")
    public CommonResult<Boolean> deleteAuth(@RequestParam("id") Long id) {
        authService.deleteAuth(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得认证")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('vrs:auth:query')")
    public CommonResult<AuthRespVO> getAuth(@RequestParam("id") Long id) {
        AuthRespVO auth = authService.getAuth(id);
        return success(auth);
    }

    @GetMapping("/page")
    @Operation(summary = "获得认证分页")
    @PreAuthorize("@ss.hasPermission('vrs:auth:query')")
    public CommonResult<PageResult<AuthRespVO>> getAuthPage(@Valid AuthPageReqVO pageReqVO) {
        PageResult<AuthRespVO> pageResult = authService.getAuthPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AuthRespVO.class));
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出认证 Excel")
//    @PreAuthorize("@ss.hasPermission('vrs:auth:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportAuthExcel(@Valid AuthPageReqVO pageReqVO,
//                                HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<AuthDO> list = authService.getAuthPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "认证.xls", "数据", AuthRespVO.class,
//                BeanUtils.toBean(list, AuthRespVO.class));
//    }

}